<%-- 
    Document   : ViewMembers
    Created on : Dec 5, 2011, 4:26:59 AM
    Author     : Joshua Suzuki
--%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<%
    String circleID;
    if(request.getParameterNames().hasMoreElements()==false)
    {
        circleID=session.getAttribute("CIRC").toString();
    }
    circleID = request.getParameter("CIRC");
    String circleName=request.getParameter("NAME");
    int usrID = Integer.parseInt(session.getAttribute("UserID").toString());
    int ownerID= Integer.parseInt(request.getParameter("OWNR"));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function row_custclick(txt)
{
    //document.forms[txt].submit();
}

function row_mousehover(obj)
{
	obj.style.backgroundColor="#6699FF";
}

function row_mouseout(obj)
{
	obj.style.backgroundColor="";
}

function onpageload()
{
<% 
if(session.getAttribute("UserID")!=null) { %>
    //window.top.location="profile.jsp"
    <% }  %>
}

</script>
</head>

<body onload="onpageload()">
<table width="500" border="0">
  <tr>
          <button  onclick="window.location='CirclePage.jsp'" >Return</button><br />
  <td align="center"><h2>Members of <%=circleName%></h2></td></tr>
      
   <tr>
    <td>
    <table width="500" border="1" >
    	<tr>
        <td width="167">First Name</td>
        <td width="167">Last Name</td>
        <td width="166">Email</td>
        
        </tr>
        <% 
            
            Connection conn = null;
            try
            {

                conn = new DBClasses.GetConnection().getConnection();
                String sql = "SELECT C.* "
                + "FROM Customer C, Circlemembership M "
                + "WHERE C.CustomerID = M.CustomerID "
                + "AND M.CircleID = "+circleID;

                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery(sql);

                int i=0;
                while(rs.next())
                {
                    int custID = Integer.parseInt(rs.getString("CustomerID"));
        %>
        <tr onclick="row_custclick('<%="cust" + i %>')" onmouseout="row_mouseout(this)" onmouseover="row_mousehover(this)">
        <form name="<%="cust" + i %>" action= "" method="post">
        <td width="167"><%=rs.getString("Firstname")%></td>
        <td width="167"><%=rs.getString("Lastname")%></td>
        <td width="166"><%=rs.getString("Email")%></td>
        </form>
        <%
            if(usrID==ownerID&&custID!=ownerID)
            {
        %> 
        <form name="<%="f"+i%>" action = "removeMember.jsp" method= "post">
            <input type="hidden" name="CUST" value="<%=custID%>"/>
            <input type="hidden" name="CIRC" value="<%=circleID%>"/>
            <td>
                <input type="button" value="remove" onclick= "document.<%="f"+i%>.submit()"/>
            </td>
        </form>
        <%
            }
        %>
        </tr>
        <%
                        i++;
                   }
           }
           catch(Exception e)
           {
               e.printStackTrace();
           }

           finally
           {
               try{
               conn.close(); }
               catch(Exception e) {
                   e.printStackTrace();
               }
           }
        %>
    </table>
    </td>
  </tr>
  <tr>
      
  </tr>
</table>
</body>
</html>
